const db = require('./lib/db');
const logger = require('../util/log');

const TAG = 'DEVICE';

/**
 * 记录设备信息
 * 兼容旧的micropython heartbeat接口
 * @param {*} event 
 */
async function handleDevice(request, event) {
    try {
        const { device_id } = event;
        if (device_id) {
            const is_exist = await db.query_device_exist(device_id);

            if (!is_exist) {
                db.insert_new_device(event);
            } else {
                db.update_device_record(event);
            }
        }
    } catch (e) {
        // console.error(e);
    }
}

module.exports = {
    handleDevice
}